package com.cq.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.cq.system.domain.SxAttr;
import com.cq.system.service.ISxAttrService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 属性Controller
 * 
 * @author cq
 * @date 2024-05-08
 */
@RestController
@RequestMapping("/system/attr")
public class SxAttrController extends BaseController
{
    @Autowired
    private ISxAttrService sxAttrService;

    /**
     * 查询属性列表
     */
    @PreAuthorize("@ss.hasPermi('system:attr:list')")
    @GetMapping("/list")
    public TableDataInfo list(SxAttr sxAttr)
    {
        startPage();
        List<SxAttr> list = sxAttrService.selectSxAttrList(sxAttr);
        return getDataTable(list);
    }

    /**
     * 导出属性列表
     */
    @PreAuthorize("@ss.hasPermi('system:attr:export')")
    @Log(title = "属性", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SxAttr sxAttr)
    {
        List<SxAttr> list = sxAttrService.selectSxAttrList(sxAttr);
        ExcelUtil<SxAttr> util = new ExcelUtil<SxAttr>(SxAttr.class);
        util.exportExcel(response, list, "属性数据");
    }

    /**
     * 获取属性详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:attr:query')")
    @GetMapping(value = "/{attrId}")
    public AjaxResult getInfo(@PathVariable("attrId") Long attrId)
    {
        return success(sxAttrService.selectSxAttrByAttrId(attrId));
    }

    /**
     * 新增属性
     */
    @PreAuthorize("@ss.hasPermi('system:attr:add')")
    @Log(title = "属性", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SxAttr sxAttr)
    {
        return toAjax(sxAttrService.insertSxAttr(sxAttr));
    }

    /**
     * 修改属性
     */
    @PreAuthorize("@ss.hasPermi('system:attr:edit')")
    @Log(title = "属性", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SxAttr sxAttr)
    {
        return toAjax(sxAttrService.updateSxAttr(sxAttr));
    }

    /**
     * 删除属性
     */
    @PreAuthorize("@ss.hasPermi('system:attr:remove')")
    @Log(title = "属性", businessType = BusinessType.DELETE)
	@DeleteMapping("/{attrIds}")
    public AjaxResult remove(@PathVariable Long[] attrIds)
    {
        return toAjax(sxAttrService.deleteSxAttrByAttrIds(attrIds));
    }
}
